package org.budo.graph.entity;

import java.util.LinkedHashMap;
import java.util.Map;

import org.apache.commons.lang3.math.NumberUtils;

import lombok.Getter;
import lombok.Setter;

/**
 * @author limingwei
 */
@Getter
@Setter
public class SpringGraph {
    public static final String GRAPH_TYPE = "SPRING";

    private static final String EXECUTE_COUNT = "ExecuteCount", EXECUTE_TIME_MILLIS = "ExecuteTimeMillis";

    public static final String[] TITLES = { EXECUTE_COUNT, EXECUTE_TIME_MILLIS };

    private Long executeCount;

    private Long executeTimeMillis;

    public SpringGraph(Map<String, Object> methodStatMap) {
        Object executeCount = methodStatMap.get(EXECUTE_COUNT);
        this.setExecuteCount(NumberUtils.toLong(executeCount + "", 0L));

        Object executeTimeMillis = methodStatMap.get(EXECUTE_TIME_MILLIS);
        this.setExecuteTimeMillis(NumberUtils.toLong(executeTimeMillis + "", 0L));
    }

    public Map<String, String> minus(SpringGraph lastSpringGraph) {
        Map<String, String> minusMap = new LinkedHashMap<String, String>(); // 这里应该是需要有序的Map的，顺序应该和 TITLES 一致
        minusMap.put(EXECUTE_COUNT, (this.getExecuteCount() - lastSpringGraph.getExecuteCount()) + ""); // 这里存储的是增量
        minusMap.put(EXECUTE_TIME_MILLIS, (this.getExecuteTimeMillis() - lastSpringGraph.getExecuteTimeMillis()) + ""); // 这里存储的是增量
        return minusMap;
    }
}